1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.DropDown; 26 27 private import gio.ListModelIF; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.Expression; 33 private import gtk.ListItemFactory; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * `GtkDropDown` is a widget that allows the user to choose an item 42 * from a list of options. 43 * 44 *  45 * 46 * The `GtkDropDown` displays the selected choice. 47 * 48 * The options are given to `GtkDropDown` in the form of `GListModel` 49 * and how the individual options are represented is determined by 50 * a [class@Gtk.ListItemFactory]. The default factory displays simple strings. 51 * 52 * `GtkDropDown` knows how to obtain strings from the items in a 53 * [class@Gtk.StringList]; for other models, you have to provide an expression 54 * to find the strings via [method@Gtk.DropDown.set_expression]. 55 * 56 * `GtkDropDown` can optionally allow search in the popup, which is 57 * useful if the list of options is long. To enable the search entry, 58 * use [method@Gtk.DropDown.set_enable_search]. 59 * 60 * # CSS nodes 61 * 62 * `GtkDropDown` has a single CSS node with name dropdown, 63 * with the button and popover nodes as children. 64 * 65 * # Accessibility 66 * 67 * `GtkDropDown` uses the %GTK_ACCESSIBLE_ROLE_COMBO_BOX role. 68 */ 69 public class DropDown : Widget 70 { 71 /** the main Gtk struct */ 72 protected GtkDropDown* gtkDropDown; 73 74 /** Get the main Gtk struct */ 75 public GtkDropDown* getDropDownStruct(bool transferOwnership = false) 76 { 77 if (transferOwnership) 78 ownedRef = false; 79 return gtkDropDown; 80 } 81 82 /** the main Gtk struct as a void* */ 83 protected override void* getStruct() 84 { 85 return cast(void*)gtkDropDown; 86 } 87 88 /** 89 * Sets our main struct and passes it to the parent class. 90 */ 91 public this (GtkDropDown* gtkDropDown, bool ownedRef = false) 92 { 93 this.gtkDropDown = gtkDropDown; 94 super(cast(GtkWidget*)gtkDropDown, ownedRef); 95 } 96 97 98 /** */ 99 public static GType getType() 100 { 101 return gtk_drop_down_get_type(); 102 } 103 104 /** 105 * Creates a new `GtkDropDown`. 106 * 107 * You may want to call [method@Gtk.DropDown.set_factory] 108 * to set up a way to map its items to widgets. 109 * 110 * Params: 111 * model = the model to use 112 * expression = the expression to use 113 * 114 * Returns: a new `GtkDropDown` 115 * 116 * Throws: ConstructionException GTK+ fails to create the object. 117 */ 118 public this(ListModelIF model, Expression expression) 119 { 120 auto __p = gtk_drop_down_new((model is null) ? null : model.getListModelStruct(), (expression is null) ? null : expression.getExpressionStruct(true)); 121 122 if(__p is null) 123 { 124 throw new ConstructionException("null returned by new"); 125 } 126 127 this(cast(GtkDropDown*) __p); 128 } 129 130 /** 131 * Creates a new `GtkDropDown` that is populated with 132 * the strings. 133 * 134 * Params: 135 * strings = The strings to put in the dropdown 136 * 137 * Returns: a new `GtkDropDown` 138 * 139 * Throws: ConstructionException GTK+ fails to create the object. 140 */ 141 public this(string[] strings) 142 { 143 auto __p = gtk_drop_down_new_from_strings(Str.toStringzArray(strings)); 144 145 if(__p is null) 146 { 147 throw new ConstructionException("null returned by new_from_strings"); 148 } 149 150 this(cast(GtkDropDown*) __p); 151 } 152 153 /** 154 * Returns whether search is enabled. 155 * 156 * Returns: %TRUE if the popup includes a search entry 157 */ 158 public bool getEnableSearch() 159 { 160 return gtk_drop_down_get_enable_search(gtkDropDown) != 0; 161 } 162 163 /** 164 * Gets the expression set that is used to obtain strings from items. 165 * 166 * See [method@Gtk.DropDown.set_expression]. 167 * 168 * Returns: a `GtkExpression` 169 */ 170 public Expression getExpression() 171 { 172 auto __p = gtk_drop_down_get_expression(gtkDropDown); 173 174 if(__p is null) 175 { 176 return null; 177 } 178 179 return ObjectG.getDObject!(Expression)(cast(GtkExpression*) __p); 180 } 181 182 /** 183 * Gets the factory that's currently used to populate list items. 184 * 185 * The factory returned by this function is always used for the 186 * item in the button. It is also used for items in the popup 187 * if [property@Gtk.DropDown:list-factory] is not set. 188 * 189 * Returns: The factory in use 190 */ 191 public ListItemFactory getFactory() 192 { 193 auto __p = gtk_drop_down_get_factory(gtkDropDown); 194 195 if(__p is null) 196 { 197 return null; 198 } 199 200 return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p); 201 } 202 203 /** 204 * Gets the factory that's currently used to populate list items in the popup. 205 * 206 * Returns: The factory in use 207 */ 208 public ListItemFactory getListFactory() 209 { 210 auto __p = gtk_drop_down_get_list_factory(gtkDropDown); 211 212 if(__p is null) 213 { 214 return null; 215 } 216 217 return ObjectG.getDObject!(ListItemFactory)(cast(GtkListItemFactory*) __p); 218 } 219 220 /** 221 * Gets the model that provides the displayed items. 222 * 223 * Returns: The model in use 224 */ 225 public ListModelIF getModel() 226 { 227 auto __p = gtk_drop_down_get_model(gtkDropDown); 228 229 if(__p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p); 235 } 236 237 /** 238 * Gets the position of the selected item. 239 * 240 * Returns: the position of the selected item, or %GTK_INVALID_LIST_POSITION 241 * if not item is selected 242 */ 243 public uint getSelected() 244 { 245 return gtk_drop_down_get_selected(gtkDropDown); 246 } 247 248 /** 249 * Gets the selected item. If no item is selected, %NULL is returned. 250 * 251 * Returns: The selected item 252 */ 253 public ObjectG getSelectedItem() 254 { 255 auto __p = gtk_drop_down_get_selected_item(gtkDropDown); 256 257 if(__p is null) 258 { 259 return null; 260 } 261 262 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p); 263 } 264 265 /** 266 * Returns whether to show an arrow within the widget. 267 * 268 * Returns: %TRUE if an arrow will be shown. 269 * 270 * Since: 4.6 271 */ 272 public bool getShowArrow() 273 { 274 return gtk_drop_down_get_show_arrow(gtkDropDown) != 0; 275 } 276 277 /** 278 * Sets whether a search entry will be shown in the popup that 279 * allows to search for items in the list. 280 * 281 * Note that [property@Gtk.DropDown:expression] must be set for 282 * search to work. 283 * 284 * Params: 285 * enableSearch = whether to enable search 286 */ 287 public void setEnableSearch(bool enableSearch) 288 { 289 gtk_drop_down_set_enable_search(gtkDropDown, enableSearch); 290 } 291 292 /** 293 * Sets the expression that gets evaluated to obtain strings from items. 294 * 295 * This is used for search in the popup. The expression must have 296 * a value type of %G_TYPE_STRING. 297 * 298 * Params: 299 * expression = a `GtkExpression` 300 */ 301 public void setExpression(Expression expression) 302 { 303 gtk_drop_down_set_expression(gtkDropDown, (expression is null) ? null : expression.getExpressionStruct()); 304 } 305 306 /** 307 * Sets the `GtkListItemFactory` to use for populating list items. 308 * 309 * Params: 310 * factory = the factory to use 311 */ 312 public void setFactory(ListItemFactory factory) 313 { 314 gtk_drop_down_set_factory(gtkDropDown, (factory is null) ? null : factory.getListItemFactoryStruct()); 315 } 316 317 /** 318 * Sets the `GtkListItemFactory` to use for populating list items in the popup. 319 * 320 * Params: 321 * factory = the factory to use 322 */ 323 public void setListFactory(ListItemFactory factory) 324 { 325 gtk_drop_down_set_list_factory(gtkDropDown, (factory is null) ? null : factory.getListItemFactoryStruct()); 326 } 327 328 /** 329 * Sets the `GListModel` to use. 330 * 331 * Params: 332 * model = the model to use 333 */ 334 public void setModel(ListModelIF model) 335 { 336 gtk_drop_down_set_model(gtkDropDown, (model is null) ? null : model.getListModelStruct()); 337 } 338 339 /** 340 * Selects the item at the given position. 341 * 342 * Params: 343 * position = the position of the item to select, or %GTK_INVALID_LIST_POSITION 344 */ 345 public void setSelected(uint position) 346 { 347 gtk_drop_down_set_selected(gtkDropDown, position); 348 } 349 350 /** 351 * Sets whether an arrow will be displayed within the widget. 352 * 353 * Params: 354 * showArrow = whether to show an arrow within the widget 355 * 356 * Since: 4.6 357 */ 358 public void setShowArrow(bool showArrow) 359 { 360 gtk_drop_down_set_show_arrow(gtkDropDown, showArrow); 361 } 362 363 /** 364 * Emitted to when the drop down is activated. 365 * 366 * The `::activate` signal on `GtkDropDown` is an action signal and 367 * emitting it causes the drop down to pop up its dropdown. 368 * 369 * Since: 4.6 370 */ 371 gulong addOnActivate(void delegate(DropDown) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 372 { 373 return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED); 374 } 375 }